



//
//  NRankViewController.m
//  nncloud
//
//  Created by macfai on 2018/11/23.
//  Copyright © 2018 macfai. All rights reserved.
//

#import "NRankViewController.h"
#import "NRankCell.h"
#import "NScoreModel.h"
@interface NRankViewController ()<UITableViewDelegate,UITableViewDataSource>

@property (nonatomic,strong)UITableView *tableView;

@property (nonatomic,strong)NSMutableArray *dataArray;

@property (nonatomic,strong)NSArray *titles;

@end

@implementation NRankViewController

#define cellIdentifier  @"rank"
#define SectionHeaderHeight 10.f

-(UITableView *)tableView{
    
    if (!_tableView) {
        
//        WeakStament(ws);
        
        _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0 , 0, ScreenWidth , ScreenHeight - 64) style:UITableViewStylePlain];
        _tableView.delegate = self;
        _tableView.dataSource = self;
        _tableView.rowHeight = 70.f;
        //        _tableView.separatorColor = [UIColor clearColor];
        _tableView.backgroundColor = kBackgroundColor;
        //        [_tableView registerNib:[UINib nibWithNibName:@"NQiyebanshiCell" bundle:nil] forCellReuseIdentifier:cellIdentifier];
        [_tableView registerNib:[UINib nibWithNibName:@"NRankCell" bundle:nil] forCellReuseIdentifier:cellIdentifier];
        
        //        _tableView.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
        //                        [ws loadData];
        //        }];
        //        _tableView.mj_footer = [MJRefreshAutoNormalFooter footerWithRefreshingBlock:^{
        //            [ws loadMoreData];
        //        }];
        _tableView.showsVerticalScrollIndicator = NO;
        _tableView.tableFooterView = [UIView new];
        
    }
    return _tableView;
}

- (void)viewDidLoad {
    
    [super viewDidLoad];
    self.view.backgroundColor = kWhiteColor;
    
    self.dataArray = [NSMutableArray array];
    [self.navigationItem setItemWithTitle:@"积分排名" textColor:kNavigationTitleColor fontSize:18 itemType:center];
    
    [self.view addSubview:self.tableView];
    
    [self loadData];
}


- (void)loadData{
    
    //后期逐渐添加参数目前不需要参数
    [[NNRCNetRequest manager]getWithUrl:kScoreRankUrl params:nil success:^(id result) {
        
        YYLog(@"%@",result);
        WeakStament(ws);
        if ([[result objectForKey:@"code"] integerValue] == 0) {
            
            NSArray *arr = result[@"page"][@"records"];
            YYLog(@"%@",arr);
            for (NSDictionary *dict in arr) {
               NScoreModel  *model = [NScoreModel mj_objectWithKeyValues:dict];
                [ws.dataArray addObject:model];
            }
            [ws.tableView reloadData];
            
        }else{
            [AFToast showText:result[@"msg"]];
        }
        
    } failure:^(id failure) {
        
    }];
    
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
//    return self.titles.count;
    return self.dataArray.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    
    NScoreModel *model = self.dataArray[indexPath.row];
    NRankCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier forIndexPath:indexPath];
    cell.nameLabel.text = [NSString stringWithFormat:@"%ld",indexPath.row+1];

    
    cell.model = model;
    return cell;
}


#pragma mark - section head
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return SectionHeaderHeight;//如果设置section的header高度，不设置footer高度，footer默认等于header高度
}



- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    
    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, SectionHeaderHeight)];
    view.backgroundColor = kBackgroundColor;
    return view;
}

#pragma mark - section foot
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    return 0;
}

- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
    return nil;
}


@end
